
package newcrunch.codeanalysis;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import javax.swing.SwingWorker;

/**
 *
 * @author WL
 */
public class FindBugsOutStream extends PrintStream
{
    private ByteArrayOutputStream bos;
    private SwingWorker<InfoNode, Void> worker;
    
    public FindBugsOutStream(SwingWorker<InfoNode, Void> worker, ByteArrayOutputStream bos)
    {
        super(bos);
        this.bos = bos;
        this.worker = worker;
    }
    
    @Override
    public void print(String string)
    {
        worker.firePropertyChange("newstatus", null, string.trim());
        int end = -1;
        int start = -1;
        if ((start = string.indexOf("-")) != -1 && 
                (end = string.indexOf("%")) != -1)
        {
            int val = Integer.parseInt(string.substring(start + 2, end));
            worker.firePropertyChange("progress", null, val);
        }
    }
}
